package com.wbs.shop.nuby.view.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Gravity;

import androidx.annotation.Nullable;
import androidx.drawerlayout.widget.DrawerLayout;

import com.wbs.shop.nuby.R;
import com.wbs.shop.nuby.bean.GoodsShowBean;
import com.wbs.shop.nuby.utils.ActivityManger;
import com.wbs.shop.nuby.view.base.BaseActivity;
import com.wbs.shop.nuby.view.fragment.CashierFragment;
import com.wbs.shop.nuby.view.fragment.CashierPayFragment;
import com.wbs.shop.nuby.view.fragment.SelectEmployeeFragment;

import java.util.List;

import butterknife.BindView;
import me.jessyan.autosize.internal.CancelAdapt;

public class CashierActivityPadActivity extends BaseActivity implements CancelAdapt {
    @BindView(R.id.drawerLayout)
    DrawerLayout drawerLayout;
    private CashierFragment mCashierFragment;
    private CashierPayFragment mCashierPayFragment;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_cashier_pad);
//        ActivityManger.finishAppointActivity(CashierActivityPadActivity.class);
        mCashierFragment = CashierFragment.newInstance(true);
        mCashierPayFragment = CashierPayFragment.newInstance(true);
        getSupportFragmentManager().beginTransaction().replace(R.id.frameLayout1, mCashierFragment).commitAllowingStateLoss();
        getSupportFragmentManager().beginTransaction().replace(R.id.frameLayout2, mCashierPayFragment).commitAllowingStateLoss();
        getSupportFragmentManager().beginTransaction().replace(R.id.frameLayoutEmployee, SelectEmployeeFragment.newInstance(true)).commitAllowingStateLoss();
        drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
    }

    public void changeGoods(List<GoodsShowBean> goodsShowBeans, String payAmount) {
        if (mCashierPayFragment != null && mCashierPayFragment.isAdded()) {
            mCashierPayFragment.changeGoods(goodsShowBeans, payAmount);
        }
    }

    public void clearCart() {
        if (mCashierFragment != null && mCashierFragment.isAdded()) {
            mCashierFragment.doClearCar();
        }
    }

    public void changeDiscount(double discount) {
        if (mCashierFragment != null && mCashierFragment.isAdded()) {
            mCashierFragment.changeDiscount(discount);
        }
    }

    public void onActivityResultEmployee(Intent data) {
        if (mCashierPayFragment != null && mCashierPayFragment.isAdded()) {
            mCashierPayFragment.onActivityResult(CashierPayFragment.REQUEST_CODE_EMPLOYEE, Activity.RESULT_OK, data);
        }
    }

    public void openEmployee() {
        drawerLayout.openDrawer(Gravity.RIGHT);
    }

    public void closeDrawers() {
        drawerLayout.closeDrawers();
    }
}
